package com.baikeyang.app.aspect;

import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.annotation.*;
import org.springframework.stereotype.Component;

@Aspect
@Component
public class MyAspect {

	private final static Logger log = LogManager.getLogger(MyAspect.class);

	@Pointcut("execution (* com.baikeyang.service.*.*.*Impl.*(..))")
	private void anyMethod() {
	}// 声明一个切入点

	@Before("anyMethod() && args(name)")
	public void doAccessCheck(String name) {
		log.info("前置通知:" + name);
	}

	@AfterReturning(pointcut = "anyMethod()", returning = "result")
	public void doAfterReturning(String result) {
		log.info("后置通知:" + result);
	}

	@After("anyMethod()")
	public void doAfter() {
		log.info("最终通知");
	}

	@AfterThrowing(pointcut = "anyMethod()", throwing = "e")
	public void doAfterThrowing(Exception e) {
		log.info("例外通知:" + e);
	}

	@Around("anyMethod()")
	public Object doBasicProfiling(ProceedingJoinPoint pjp) throws Throwable {
		// if(){//判断用户是否在权限
		log.info("进入方法");
		Object result = pjp.proceed();
		log.info("退出方法");
		// }
		return result;
	}


}
